{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<img align=\"left\" style=\"padding-right:10px;\" src=\"figures/PHydro-cover-small.png\">\n",
    "*This is the Jupyter notebook version of the [Python in Hydrology](http://www.greenteapress.com/pythonhydro/pythonhydro.html) by Sat Kumar Tomer.*\n",
    "*Source code is available at [code.google.com](https://code.google.com/archive/p/python-in-hydrology/source).*\n",
    "\n",
    "*The book is available under the [GNU Free Documentation License](http://www.gnu.org/copyleft/fdl.html). If you have comments, corrections or suggestions, please send email to satkumartomer@gmail.com.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Python Installation](01.02-Python-Installation.ipynb) | [Contents](Index.ipynb) | [Interactive Development Environment](01.04-Interactive-evelopment-Environment.ipynb) >"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.3 其他程序包的安装\n",
    "\n",
    "`pip`是Python中安装其他程序包非常有用的方式。在安装`pip`之前，`distribute`应该被安装。首先，我们需要下载`Distribute`,通过从`http://python-distribute.org/distribute_setup.py`下载`distribute_setup.py`,并运行如下命令：\n",
    "\n",
    "```\n",
    "$ sudo python distribute_setup.py\n",
    "```\n",
    "现在，可以从`https://github.com/pypa/pip/raw/master/contrib/get-pip.py`下载`get-pip.py`,并以root身份运行：\n",
    "\n",
    "```\n",
    "$  sudo python get-pip.py\n",
    "```\n",
    "\n",
    "请注意，`distribute_setup.py`和`get-pip.py`在安装时需要位于当前工作目录中，否则的话，请提供完整的文件路径名。如果在此过程中并未遇到任何错误，`pip`应该准备好安装新的程序包了。安装程序包的过程是很简单的，例如，假设你想要安装程序包`SomePackage`，即运行如下命令：\n",
    "\n",
    "```\n",
    "$ sudo pip install SomePackage\n",
    "```\n",
    "在水文学中，频繁使用到的程序包有`Numpy`,`Scipy`,`xlrd`,`xlwt`,以及`gdal`，所以需要在本阶段安装这些包。以后每当需要安装新的程序包/库时，都可以按照下面给出的方式下载。\n",
    "\n",
    "```\n",
    "$ sudo pip install Numpy\n",
    "$ sudo pip install Scipy\n",
    "$ sudo pip install xlrd\n",
    "$ sudo pip install xlwt\n",
    "$ sudo pip install gdal\n",
    "```\n",
    "这些程序包/库可以通过在一行指令中指定所有程序包名称安装，即`$ sudo pip install Numpy Scipy xlrd xlwt gdal`。但是最好在单独的命令行中安装它们，这样有助于你在安装时遇到些错误时，容易的发现哪个程序包安装时出错了。最常见的问题是`pip`指令无法从网络中下载这些程序包/库。在这种情况下，你可以使用浏览器下载`*.tar.gz`库，并且按照如下方式运行`pip`：\n",
    "\n",
    "```\n",
    "$ sudo pip install /path/to/*.tar.gz\n",
    "```\n",
    "\n",
    "此外，window用户可以下载`*.exe`或`*.msi`文件，如果文件可用的话，可以通过双击进行下载。\n",
    "\n",
    "如果上述操作也失败了，作为最后一个选项，你可以下载`*.tar.gz`文件进行解压。然后，在解压后的文件夹目录中，你应该可以发现`setup.py`文件在里面。现在，运行下面的命令：\n",
    "\n",
    "```\n",
    "$ sudo python setup.py install\n",
    "```\n",
    "如果你看到任何错误，这可能是由于某些相关依赖包或库在你的计算机中不可用。你应该阅读随包提供的`README`文件，它可以为您提供所需程序包/库的详细信息，以及如何安装它们。\n",
    "\n",
    "以下面的方式使用`pip`对程序包/库进行升级\n",
    "\n",
    "```\n",
    "$ sudo pip install --upgrade some_package\n",
    "```"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
